package com.bobo.web.provider.config;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * yangbo
 * 2019-11-20
 * basketball-web
 **/
public class DBContextHolder {
    private static final ThreadLocal<DBTypeEnum> contextHolder = new ThreadLocal<>();

    private static final AtomicInteger counter = new AtomicInteger(-1);

    public static void set(DBTypeEnum dbType) {
        contextHolder.set(dbType);
    }

    public static DBTypeEnum get() {
        return contextHolder.get();
    }

    public static void master() {
        set(DBTypeEnum.MASTER);
        System.out.println("选择主库---master");
    }

    public static void slave() {
        /**
         * 如果有多个从库，在此设置切换从库的方式，轮训或随机
         */
        set(DBTypeEnum.SLAVE);
        System.out.println("选择从库--salve");
    }
}
